package com.night.icm.persistence.base.repository;

import com.night.icm.persistence.base.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * StudentRepository
 *
 * @author Liao ZhiYong
 * @date 2020/1/29
 */
@Repository
public interface StudentRepository extends JpaRepository<Student, Long>, JpaSpecificationExecutor<Student> {

    /**
     * 根据code查找学生
     *
     * @param code code
     * @return 学生
     */
    Student findByCode(String code);

    /**
     * 根据userId查找学生
     *
     * @param userId userId
     */
    @Query("from Student as s where s.user.id = :userId")
    Student findByUserId(@Param("userId") Integer userId);
}
